package sz.szsmk.citizencard.mvp.presenter;

import javax.inject.Inject;

import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.QueryBusStandBykeyReq;
import sz.szsmk.citizencard.model.network.bean.response.QueryNearStandbyRes;
import sz.szsmk.citizencard.mvp.contract.IBusSiteSearchContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/11/15 9:52
 * description:
 */
public class BusSiteSearchPresenter extends IBasePresenter
        implements IBusSiteSearchContact.IBusSiteSearchPresenter<IBusSiteSearchContact.IBusSiteSearchView> {


    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public BusSiteSearchPresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;

        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    @Override
    public void getSearchList(String s, String keyword) {
        QueryBusStandBykeyReq queryBusStandBykeyReq = new QueryBusStandBykeyReq();
        queryBusStandBykeyReq.setStand_key_name(s);
        queryBusStandBykeyReq.setUserID(keyword);
        mNetworkDateSource.queryBusStandByKey(queryBusStandBykeyReq, new SubscribeResult<QueryNearStandbyRes>() {
            @Override
            protected void onOk(QueryNearStandbyRes response) {
                ((IBusSiteSearchContact.IBusSiteSearchView) mView).getSearchListSucc(response);
            }

            @Override
            protected void onFailure(QueryNearStandbyRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }
}
